//
//  TypeDefineTableViewCell.m
//  KeleAppProject
//
//  Created by Cen Zhou on 2018/1/17.
//  Copyright © 2018年 Cen Zhou. All rights reserved.
//

#import "TypeDefineTableViewCell.h"
#import "CellTintModel.h"
@interface TypeDefineTableViewCell()


@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) UILabel *tintLb;
@end

@implementation TypeDefineTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier
                         type:(NSInteger)type{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self loadSubviewsWithType:type];
    }
    return self;
}

- (void)loadSubviewsWithType:(NSInteger)type{
    
    UILabel *tintLb = [[UILabel alloc]init];
    tintLb.text = @"题目";
    tintLb.textColor = KLColor_B6;
    tintLb.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16*WIDTH];
    [self.contentView addSubview:tintLb];
    self.tintLb = tintLb;
    [tintLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(15*WIDTH);
    }];
    if (type==DefineCellTypeInSecond) {
        UIImageView *inSecondImg = [[UIImageView alloc]init];
        inSecondImg.image = [UIImage imageNamed:@"info_icon_into"];
        [self.contentView addSubview:inSecondImg];
        [inSecondImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-15*WIDTH);
        }];
    }else if (type == DefineCellTypeInfoTint){
        UILabel *contentLb = [[UILabel alloc]init];
        contentLb.text = @"内容";
        contentLb.textColor = KLColor_B5;
        contentLb.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14*WIDTH];
        [self.contentView addSubview:contentLb];
        self.infoTint = contentLb;
        [contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-15*WIDTH);
        }];
    }else if (type == DefineCellTypeSwitch){
        UISwitch *switchBtn = [[UISwitch alloc]init];
        switchBtn.onTintColor = KLColor_A1;
        [self.contentView addSubview:switchBtn];
        [switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-15*WIDTH);
        }];
    }else if (type == DefineCellTypeImageAndInSecond){
        UIImageView *inSecondImg = [[UIImageView alloc]init];
        inSecondImg.image = [UIImage imageNamed:@"info_icon_into"];
        [self.contentView addSubview:inSecondImg];
        [inSecondImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-15*WIDTH);
        }];
        
        UIImageView *profileImageView = [[UIImageView alloc]init];
        profileImageView.image = [UIImage imageNamed:@"info_touxiang"];
        profileImageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:profileImageView];
//        profileImageView.layer.masksToBounds = YES;
//        profileImageView.layer.cornerRadius = 13*WIDTH;
        self.cellImageView = profileImageView;
        [profileImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-33*WIDTH);
            make.width.height.mas_equalTo(26*WIDTH);
        }];
        
    }else if (type == DefineCellTypeTintAndInSecond){
        UIImageView *inSecondImg = [[UIImageView alloc]init];
        inSecondImg.image = [UIImage imageNamed:@"info_icon_into"];
        [self.contentView addSubview:inSecondImg];
        [inSecondImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-15*WIDTH);
        }];
        
        UILabel *contentLb = [[UILabel alloc]init];
        contentLb.text = @"内容";
        contentLb.textColor = KLColor_B5;
        contentLb.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14*WIDTH];
        [self.contentView addSubview:contentLb];
        self.infoTint = contentLb;
        [contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-33*WIDTH);
        }];
    }
    
    
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = KLColor_B3;
    [self.contentView addSubview:lineView];
    self.lineView = lineView;
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.right.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(15*WIDTH);
        make.height.mas_equalTo(1);
    }];
    
}


- (void)setModel:(CellTintModel *)model{
    self.tintLb.text = model.tint;
}

- (void)setIsShowLine:(BOOL)isShowLine{
    self.lineView.hidden = isShowLine;
}


- (void)layoutSublayersOfLayer:(CALayer *)layer{
    [super layoutSublayersOfLayer:layer];
    [self.cellImageView layoutIfNeeded];
    [self.cellImageView setRadiusWithValue:13*WIDTH];
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
